package other.mvvm.activity.src.app_package.setting

import com.android.tools.idea.wizard.template.*
import com.android.tools.idea.wizard.template.impl.activities.common.MIN_API
import other.mvvm.activity.src.app_package.defaultPackageNameParameter


val settingActivityTemplate
    get() = template {
        name = "MVVM recyclerview Activity"
        description = "recyclerview + adapter"
        minApi = MIN_API

        category = Category.Other
        formFactor = FormFactor.Mobile
        screens = listOf(WizardUiContext.ActivityGallery, WizardUiContext.MenuEntry, WizardUiContext.NewProject, WizardUiContext.NewModule)

        lateinit var layoutName: StringParameter

        val activityClass = stringParameter {
            name = "Activity Name"
            default = "Main"
            help = "只输入名字，不要包含Activity"
            constraints = listOf(Constraint.NONEMPTY)
        }

        layoutName = stringParameter {
            name = "Layout Name"
            default = "activity_list"
            help = "请输入布局的名字"
            constraints = listOf(Constraint.LAYOUT, Constraint.UNIQUE, Constraint.NONEMPTY)
            suggest = { "${activityToLayout(activityClass.value.toLowerCase())}" }
        }

        val adapterName= stringParameter {
            name="adapter Name"
            default="Main"
            help="请输入adapter名字"
            constraints = listOf(Constraint.NONEMPTY)
        }

        val packageName = defaultPackageNameParameter

        widgets(
                TextFieldWidget(activityClass),
                TextFieldWidget(layoutName),
                TextFieldWidget(adapterName),
                PackageNameWidget(packageName)
        )
//        thumb { File("logo.png") }
        recipe = { data: TemplateData ->
            settingMvvmActivityRecipe(
                    data as ModuleTemplateData,
                    activityClass.value,
                    layoutName.value,
                    packageName.value,adapterName.value)
        }
    }


//val defaultPackageNameParameter
//    get() = stringParameter {
//        name = "Package name"
//        visible = { !isNewModule }
//        default = "com.mycompany.myapp"
//        constraints = listOf(Constraint.PACKAGE)
//        suggest = { packageName }
//    }